# This code is hosted on http://code.google.com/p/lenthorp/
# Freely available for use in applications, but should NOT be modified
# Email all comments to lenthorpresearch@gmail.com


from PricingEngine_BlackScholesFiniteDifferenceMod import *
from PricingEngine_BlackScholesTransformedFiniteDifferenceMod import *
from PricingEngine_BlackScholesHeatEquationFiniteDifferenceMod import *
from CalibratorMod import *

def runTest():
    mp = ModelParameters()
    mp.p['type'] = 'put'
    bsmfde = BlackScholesExplicitFiniteDifferences(mp)
    ##bsmfde = BlackScholesTransformedExplicitFiniteDifferences(mp)
    ##bsmfde = BlackScholesHeatEquationExplicitFiniteDifferences(mp)
    ##bsmfde = BlackScholesImplicitFiniteDifferences(mp)
    ##bsmfde = BlackScholesTransformedImplicitFiniteDifferences(mp)
    ##bsmfde = BlackScholesHeatEquationImplicitFiniteDifferences(mp)
    op = OptimiseParameters()
    op.p['vol'] = 0.3
    pp = PricingParameters(['strike', 'tenor', 'rate', 'initial', 'div'])
    pp.addPricingSet([50.0, 5.0/12.0, 0.1, 50.0, 0],0)
    bsmfde.setUpParameters(pp,op)
    bsmfde.preComputations()
    res = []
    res.append(bsmfde.getPrice())
    
    bsmfde = BlackScholesHeatEquationExplicitFiniteDifferences(mp)
    bsmfde.setUpParameters(pp,op)
    bsmfde.preComputations()
    res.append(bsmfde.getPrice())


    ##targetPrice = 86.0
    ##pp = PricingParameters(['strike', 'tenor', 'rate', 'initial', 'div'])
    ##pp.addPricingSet([100, 30, 0.05, 100, 0], targetPrice)
    ##dm = SumOfSquaresDistance()
    ##c = ScipyFminBFGSCalibrator(bsme, pp, op, dm)
    ##print(c.calibrate())
    return res


if __name__ == "__main__":
    res = runTest()
    print(res)